package com.sq.partner.manager.dao.impl;
import com.sq.partner.manager.dao.AntPolicyAndClaimDao;
import com.sq.partner.manager.mybatis.model.AntPolicyAndClaim;
import com.sq.partner.manager.util.Page;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Repository
public class AntPolicyAndClaimDaoImpl extends BaseDaoImpl implements AntPolicyAndClaimDao {
    @Override
    public Page queryPolicyAndClaim(Page page) throws Exception {
        Map<String,Object> map = (Map<String, Object>) page.getType();
        String flag = map.get("flag").toString();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if("1".equals(flag)){
            page.setTotal((Integer)this.query("queryCount1", map));
            List<AntPolicyAndClaim> list = queryList("queryPolicyInfo", map);
            for (AntPolicyAndClaim apc:list) {
                if(null != apc.getInsureStart()){
                    Date start = sdf.parse(apc.getInsureStart());
                    apc.setInsureStart(sdf.format(start));
                }
                if(null != apc.getInsureEnd()){
                    Date end = sdf.parse(apc.getInsureEnd());
                    apc.setInsureEnd(sdf.format(end));
                }
            }
            page.setData(list);
        }
        if("2".equals(flag)){
        page.setTotal((Integer)this.query("queryCount2", map));
        List<AntPolicyAndClaim> list = queryList("queryClaimInfo", map);
        page.setData(list);
        }
        return page;
    }

	@Override
	public List<Map<String, Object>> queryPolicyByCondition(Map<String, String> map) throws Exception {
		if("1".equals(map.get("flag").toString())){
			return this.queryList("queryPolicyByCondition1", map);
		}else{
			return this.queryList("queryPolicyByCondition2", map);
		}		
	}
}
